package org.karelun.rabbit.bridge.ui.action;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.edit.command.CreateChildCommand;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.karelun.rabbit.bridge.ITransactionEditingDomain;

public class RabbitCreateSiblingAction extends RabbitStaticSelectionCommandAction{

	protected Object descriptor;
	
	public RabbitCreateSiblingAction(IWorkbenchPart workbenchPart, ISelection selection,  Object descriptor)
	  {
	    super(workbenchPart);
	    this.descriptor = descriptor;
	    configureAction(selection);
	  }
	
	 public RabbitCreateSiblingAction(IEditorPart editorPart, ISelection selection,  Object descriptor)
	  {
	    this((IWorkbenchPart)editorPart, selection, descriptor);
	  }
	 
	  public RabbitCreateSiblingAction(ITransactionEditingDomain editingDomain, ISelection selection,  Object descriptor)
	  {
	    super(editingDomain);
	    this.descriptor = descriptor;
	    configureAction(selection);
	  }
	
	@Override
	protected Command createActionCommand(ITransactionEditingDomain editingDomain,Collection<Object> collection) {
		if(collection.size()==1){
			return CreateChildCommand.create(editingDomain, null, descriptor, collection);
		}
		return UnexecutableCommand.INSTANCE;
	}

}
